import Vue from 'vue'
import Router from 'vue-router'
import pregrabcase from '@/views/pregrabcase'
import grabresult from '@/views/grabresult'
import Layout from '@/page/layout'

Vue.use(Router)

// 公共路由
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/',
    component: () => import('@/page/layout'),
    children: [
      {
        path: 'pregrabcase',
        component: pregrabcase,
        name: 'Pregrabcase',
        meta: { title: '待抢案', affix: true }
      },
      {
        path: 'grabresult',
        component: grabresult,
        name: 'Grabresult',
        meta: { title: '抢案结果', affix: true }
      }
    ]
  }
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}

export default new Router({
  base: "",
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})
